fix: OpenAI 路径添加防御性 usage 合并逻辑#1232
Conversation
将 message_delta 处理器中的 `{ ...usage, ...deltaUsage }` spread
替换为 updateOpenAIUsage() 函数,与 claude.ts 的 updateUsage() 模式
保持一致。
当前适配器发送的 message_delta 包含完整字段,spread 不会丢失数据。
但若未来适配器在某事件中省略了 cache 字段(传 explicit 0),spread
会无声覆盖有效值。新函数仅在 delta 字段有意义值时更新,否则保留
当前值。
Co-Authored-By: deepseek-v4-pro[1m] <deepseek-ai@claude-code-best.win>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe OpenAI streaming adapter adds defensive merging logic for incremental token-usage updates. A new ChangesOpenAI Token Usage Defense
Possibly related PRs
Poem
🎯 2 (Simple) | ⏱️ ~15 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Superseded by PR #1234 which extracts the same fix into a shared module (openaiShared.ts) used by both OpenAI and Grok paths. |
Summary
将 OpenAI 路径中
message_delta处理器的{ ...usage, ...deltaUsage }spread 替换为
updateOpenAIUsage()函数,与claude.ts的updateUsage()模式保持一致。
当前 OpenAI 适配器发送的
message_delta包含完整字段,spread 不会丢失数据。但若未来适配器在某事件中省略了 cache 字段(传 explicit 0),spread
会无声覆盖有效值。新函数仅在 delta 字段有意义值时更新,否则保留当前值。
Context
跨 provider 缓存兼容性分析(见 PR #1225 的后续讨论)发现:
updateUsage()做字段级保护合���{ ...usage, ...deltaUsage }spread,缺少防御message_delta处理器)Test plan
🤖 Generated with Claude Code Best
Summary by CodeRabbit